import 'package:crop_your_image/crop_your_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class CropWidget extends StatefulWidget {
  final Uint8List data;

  const CropWidget({super.key, required this.data});

  @override
  State<StatefulWidget> createState() => _CropWidgetState();
}

class _CropWidgetState extends State<CropWidget> {
  var controller = CropController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Crop(
          controller: controller,
          image: widget.data,
          onCropped: (Uint8List value) {
            Navigator.pop(context, value);
          },
          aspectRatio: 1,
        ),
      ),
      appBar: AppBar(
        title: const Text("裁剪"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          controller.crop();
        },
        child: const Icon(Icons.crop),
      ),
    );
  }
}
